<template>
  <div class="community-index">
    <div class="header">
      <div class="user" @click="goToUserPage"><img :src="avatar" class="user-img"></div>
      <div class="import" @click="importpage"><img src="@\assets\images\community\add.png" class="import-img"></div>
    </div>
    <!-- 登录确认弹窗 -->
    <div v-if="showLoginConfirm" class="login-confirm-overlay" @click="closeLoginConfirm">
      <div class="login-confirm-dialog" @click.stop>
        <div class="login-confirm-content">
          <div class="login-confirm-title">您当前未登录</div>
          <div class="login-confirm-text">登录后才能使用该功能</div>
          <div class="login-confirm-buttons">
            <button class="login-btn" @click="goToLogin">去登录</button>
            <button class="cancel-btn" @click="closeLoginConfirm">再看看</button>
          </div>
        </div>
      </div>
    </div>
    <div class="content">
      <Waterfull />
    </div>
    <footer class="footer">
      <TabNav />
    </footer>
  </div>

</template>

<script setup>
defineOptions({
  name: 'communityIndex'
})
import Waterfull from './components/Waterfull.vue'
import TabNav from '@/components/TabNav/TabNav.vue';
import { useRouter } from 'vue-router';
import { useUserStore } from '@/stores/user';
import { ref, onMounted } from 'vue'
const userStore = useUserStore();
const router = useRouter();
const showLoginConfirm = ref(false);
const avatar = ref(userStore.userInfo.userPic ? userStore.userInfo.userPic : 'src/assets/images/home/catAvatar.png')
const importpage = () => {
  if (userStore.userInfo.id) {
    router.push('/import');
  }
  else {
    showLoginConfirm.value = true;
  }
};
//头像
const goToUserPage = () => {
  if (userStore.userInfo.id) {
    router.push({ path: '/MyInfo' });
  }
  else {
    showLoginConfirm.value = true;
  }
};
// 关闭登录确认弹窗
const closeLoginConfirm = () => {
  showLoginConfirm.value = false;
};

// 去登录
const goToLogin = () => {
  router.push({ path: "/login" });
  closeLoginConfirm();
};

const goToprotdetailPage = () => {
  router.push({
    path: '/protdetail',
    name: 'ProtDetail',

  });
};
</script>

<style lang="scss" scoped>
$primary-color: #007bff;
$gray-light: #f0f0f0;
$gray: #e0e0e0;
$gray-dark: #d0d0d0;
$white: #ffffff;

.community-index {
  position: relative;

  .header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: linear-gradient(135deg, #dbd2f1, #d6d7ee);
    height: 50px;
    border-bottom: 1px solid $gray;

    .user {
      position: absolute;
      top: 10px;
      left: 10px;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      overflow: hidden;
      background-color: $gray-light;

      .user-img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }

    .import {
      position: absolute;
      top: 10px;
      right: 10px;
      width: 30px;
      height: 30px;

      .import-img {
        width: 100%;
        height: 100%;

      }
    }

    //瀑布区
    .content {

      position: absolute;
      top: 370px;
      width: 100%;
      height: 495px;

    }
  }

  .login-confirm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
  }

  .login-confirm-dialog {
    width: 80%;
    max-width: 300px;
    background-color: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }

  .login-confirm-content {
    padding: 20px;
  }

  .login-confirm-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 10px;
    text-align: center;
    color: #333;
  }

  .login-confirm-text {
    font-size: 14px;
    margin-bottom: 20px;
    text-align: center;
    color: #666;
  }

  .login-confirm-buttons {
    display: flex;
    justify-content: space-between;
  }

  .login-btn {
    flex: 1;
    margin-right: 10px;
    padding: 10px 0;
    background-color: #dbd2f1;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
  }

  .cancel-btn {
    flex: 1;
    padding: 10px 0;
    background-color: #f5f5f5;
    color: #666;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
  }
}
</style>